package com.eqs.enterprisequestionnaire.controller;

import com.eqs.enterprisequestionnaire.model.pojo.*;
import com.eqs.enterprisequestionnaire.result.R;
import com.eqs.enterprisequestionnaire.service.*;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/history")
public class HistoryController {
    @Autowired
    HistoryService historyService;
    @Autowired
    ResponseService responseService;
    @Autowired
    QuestionnaireService questionnaireService;
    @Autowired
    QuestionService questionService;
    //可以查询所有浏览问卷的id
    @GetMapping("/list1/{id}")
    public R<List<Integer>> historyListId(Integer id){
        return R.success(historyService.getListIdByUserId(id));
    }
    @GetMapping("/admin/allQuestionnaire")
    public R GetAllQuestionnaire (){
        return R.success(historyService.getAllQuestionnaire());
    }
    @GetMapping("/admin/genderQuestionnaire/{gender}")
    public R GetGenderQuestionnaire (@PathVariable boolean gender){
        return R.success(historyService.getQuestionnaireByGender(gender));
    }
    @GetMapping("/admin/enterpriseQuestionnaire/{enterprise}")
    public R GetQuestionnaireByEnterprise (@PathVariable String enterprise){
        return R.success(historyService.getQuestionnaireByEnterprise(enterprise));
    }
    @GetMapping("/admin/AgeQuestionnaire")
    public R GetQuestionnaireByAgeRange (@RequestParam Integer min,@RequestParam Integer max){
        return R.success(historyService.getQuestionnaireByAge(min,max));
    }
    //作者
    @GetMapping("/questionnaireBySelf/{userId}")
    public R GetQuestionnaireBySelf(@PathVariable Integer userId){
        return R.success(historyService.getQuestionnaireBySelf(userId));
    }
    //个人所有回应
    @GetMapping("/responsePersonally/{userId}")
    public R GetResponseByUserId(@PathVariable Integer userId){
       return R.success(historyService.getListResponseByUserId(userId));
    }
    //可以查询个人所有浏览问卷
    @GetMapping("/{id}/questionnaire")
    public R GetHistoryListQuestionnaire(@PathVariable Integer id){
        return R.success(historyService.getListQuestionnaireByUserId(id));
    }
    //查询问卷的所有问题
    @GetMapping("/{questionnaireId}/question/")
    public R<List<Question>> GetListQuestionOfQuestionnaire(@PathVariable Integer questionnaireId){
        return R.success(historyService.getListQuestionByQuestionnaireId(questionnaireId));
    }
    //查询问题的所有选项
    @GetMapping("/{questionId}/option")
    public R<List<Option>> GetListOptionOfQuestion(@PathVariable Integer questionId){
        return R.success(historyService.getListOptionByQuestionId(questionId));
    }
    //查询问题的所有答案
    @GetMapping("/{questionId}/answer")
    public R<List<Answer>> GetListAnswerOfQuestion( @PathVariable Integer questionId){
        return R.success(historyService.getListAnswerByQuestionId(questionId));
    }
    //查询个人回复中问题的所有答案
    @GetMapping("/answer/personally")
    public R<List<Answer>> GetListAnswerOfQuestionPersonally(@RequestParam Integer responseId,@RequestParam Integer questionId){
        return R.success(historyService.getAnswerOfQuestionPersonally(responseId,questionId));
    }
    //查询个人回复中问题的所有答案
    @GetMapping("/answerBySelf")
    public R<List<Answer>> GetListAnswerByUserAndQuestion(@RequestParam Integer userId,@RequestParam Integer questionId){
        return R.success(historyService.getAnswerByUserAndQuestion(userId,questionId));
    }
    //得到一个问卷的全部信息
    @GetMapping("/wholeQuestionnaire/{questionnaireId}")
    public R getWholeQuestionnaire(@PathVariable Integer questionnaireId){
        return R.success(historyService.getWholeQuestionnaire(questionnaireId));
    }
}
